package com.device.operating.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.device.operating.dao.RoleRepository;
import com.device.operating.entity.Role;
import com.device.operating.service.RoleService;

@Service("RoleService")
@Transactional(propagation=Propagation.REQUIRED)
public class RoleServiceImpl implements RoleService{
	
	@Autowired
	private RoleRepository RoleRepository;
	
	@Override
	public void addrole(Role role) {
		// TODO Auto-generated method stub
		RoleRepository.save(role);
	}

	@Override
	public void deleterole(Role role) {
		// TODO Auto-generated method stub
		RoleRepository.delete(role);
	}

	@Override
	public List<Role> queryall() {
		// TODO Auto-generated method stub
		List<Role> list=new ArrayList<Role>();
		Iterable<Role> iter =RoleRepository.findAll();
		Iterator<Role> it=iter.iterator();
		while(it.hasNext()){
			list.add(it.next());
		}
		return list;
	}

	@Override
	public Role queryone(String roleId) {
		// TODO Auto-generated method stub
		return RoleRepository.findOne(roleId);
	}
	
}
